//=================================================================
// 
// renderer.h
// 
// Written by Luke Olsen, Jan. 2004 & Steven Longay 2011
// Based on example code distributed with Qt under GPL license.
// Modified by Erika Harrison, Nov. 2010 for v4.6.3 support
//
// Provides a bare-bones implementation of a GL widget under Qt.
// Custom function declarations and class variables can be 
// added here.
// 
//=================================================================
// Modified By: Jesse Sahota
//
// I used this as template from steven longay' tutorial
// and added alot of function related to the project.
//
#ifndef RENDERER_H
#define RENDERER_H

//Just a little bit of cross platform support
#ifdef __APPLE__
#include <QtOpenGL>
#include <OpenGL/glu.h>
#else
#include <QGLWidget>
#include "GL/glu.h"
#endif
#include <QtGui>
#include "Trackball.h"
#include "Plant.h"

class Renderer : public QGLWidget
{
    Q_OBJECT

public:

    Renderer( QWidget* parent = 0 );
    ~Renderer();
    
    QSize sizeHint() const{return QSize(400,400); }
    QSizePolicy sizePolict() const {return QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); }

    void setLabelRadius(QLabel * rLabel);
    void setLabelTropism(QLabel * tLabel);
    void setLabelKill(QLabel *kLabel);
signals:
    
    
public slots:
    void animate();
    void tropismTreeModel(int coefficent);
    void simulatePlant();
    void resetTrackball();
    void savePoints();
    void loadPoints();
    void createPoints();
    void loadTexture();

    void changeTreeSize(int value);
    void changeInfluence(int value);
    void changeKill(int value);
    void changeDisapperTexture(bool clicked);

    void changeToRegularMode();
    void changeToPineMode();

    void selectSkeleton();
    void selectWireFrame();
    void selectSmoothShading();
protected:
    // These three functions are REQUIRED for GL widget to operate
    // under Qt. Add custom rendering code to renderer.cpp.
    void initializeGL();
    void paintGL();
    void resizeGL( int w, int h );
    
    // There are lots of optional events you can grab too
    void mousePressEvent( QMouseEvent *e);
    void mouseMoveEvent(QMouseEvent *e);
    void wheelEvent(QWheelEvent *e);
private:
    void lighting();
    //helper functions
    double calculateXCoord(const int & x);
    double calculateYCoord(const int & y);

    void drawTestStub();
    Trackball tracker;
    int modelYRotation;
    // Declare class variables here.
    
    double dist;
    double cameraZ;
    bool isOrthogonal;
    QTimer *timer;
    QLabel *tropLabel;
    QLabel *radLabel;
    QLabel *killLabel;

    Plant plant;
    int width, height;
    // Variables for keeping track of mouse events
    int oldx, oldy;
    int button;
    bool mousePressed;
};

#endif 

